package com.hnu.highlynewapp.app;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.hnu.highlynewapp.exception.BizCodeEnum;
import com.hnu.highlynewapp.vo.FinancialInstSearchVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hnu.highlynewapp.entity.FinancialInstitutionInfoEntity;
import com.hnu.highlynewapp.service.FinancialInstitutionInfoService;
import com.hnu.highlynewapp.utils.PageUtils;
import com.hnu.highlynewapp.utils.R;
import springfox.documentation.annotations.ApiIgnore;


/**
 * 金融机构
 *
 * @author hnu_worker
 * @email 825963704@qq.com
 * @date 2021-01-03 10:35:56
 */
@Api(tags = "角色api管理")
@RestController
@RequestMapping("/financialinstitutioninfo")
public class FinancialInstitutionInfoController {
    @Autowired
    private FinancialInstitutionInfoService financialInstitutionInfoService;

    /**
     * 根据检索条件获取对应的金融机构列表
     */
    @ApiOperation("根据检索条件获取对应的金融机构列表")
    @PostMapping("/getlist")
    public R getList(@RequestBody FinancialInstSearchVo vo){
        List<FinancialInstitutionInfoEntity> list = financialInstitutionInfoService.getListByParma(vo);

        return R.ok().put("data", list);
    }

    /**
     * 根据id获取金融机构
     */
    @ApiOperation("根据id获取金融机构")
    @GetMapping("/get/{financialInstitutionId}")
    public R getById(@PathVariable("financialInstitutionId") Long financialInstitutionId){
        FinancialInstitutionInfoEntity financialInstitutionInfo = financialInstitutionInfoService.getById(financialInstitutionId);
        if (financialInstitutionInfo == null) {
            return R.error(BizCodeEnum.INFO_NOT_FOUND_EXCEPTION.getCode(), BizCodeEnum.INFO_NOT_FOUND_EXCEPTION.getMessage());
        }
        return R.ok().put("data", financialInstitutionInfo);
    }


    /**
     * 列表
     */
    @ApiIgnore
    @RequestMapping("/list")
    //@RequiresPermissions("highlynewapp:financialinstitutioninfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = financialInstitutionInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiIgnore
    @RequestMapping("/info/{financialInstitutionId}")
    //@RequiresPermissions("highlynewapp:financialinstitutioninfo:info")
    public R info(@PathVariable("financialInstitutionId") Long financialInstitutionId){
		FinancialInstitutionInfoEntity financialInstitutionInfo = financialInstitutionInfoService.getById(financialInstitutionId);

        return R.ok().put("financialInstitutionInfo", financialInstitutionInfo);
    }

    /**
     * 保存
     */
    @ApiIgnore
    @RequestMapping("/save")
    //@RequiresPermissions("highlynewapp:financialinstitutioninfo:save")
    public R save(@RequestBody FinancialInstitutionInfoEntity financialInstitutionInfo){
		financialInstitutionInfoService.save(financialInstitutionInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @ApiIgnore
    @RequestMapping("/update")
    //@RequiresPermissions("highlynewapp:financialinstitutioninfo:update")
    public R update(@RequestBody FinancialInstitutionInfoEntity financialInstitutionInfo){
		financialInstitutionInfoService.updateById(financialInstitutionInfo);

        return R.ok();
    }

    /**
     * 删除
     */
    @ApiIgnore
    @RequestMapping("/delete")
    //@RequiresPermissions("highlynewapp:financialinstitutioninfo:delete")
    public R delete(@RequestBody Long[] financialInstitutionIds){
		financialInstitutionInfoService.removeByIds(Arrays.asList(financialInstitutionIds));

        return R.ok();
    }

}
